TQE.config.server_url_r2l='';
TQE.ajax={
	getXmlHttp:function ()
	{
		var result = false;
		if (typeof XMLHttpRequest != "undefined") {
			result = new XMLHttpRequest();
		}else{
			var xmlHttp_vers = ["Microsoft.XmlHttp","MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp"];
			for(var i=0;i<xmlHttp_vers.length;i++){
				try{
					result = new ActiveXObject(xmlHttp_vers[i]);
					break;
				}catch(e){
				}
			}
		}
		return result;
	},
	rpc:function(callback,url,data,method){
		if('undefined'==typeof data) data='';
		if('undefined'==typeof method) method='GET';
		var xmlHttp = this.getXmlHttp();
		if(false == xmlHttp){ alert('出错,浏览器不支持.'); return ;}
		try{
			xmlHttp.open(method, url, true);
			xmlHttp.onreadystatechange = function(){
				switch(this.readyState){
					case 0:break;
					case 1:break;
					case 2:break;
					case 3:break;
					case 4:if(this.status==200){
						 		callback(this.responseText);
							}else{
								alert('请求出错, 错误码:'+ this.status);
							}break;
					default:break;
				}
			};
			xmlHttp.send(data);
		}
		catch(e){
			alert(e);
		}
		return false;		
	},
	get:function(callback,url){
		return this.rpc(callback,url,null,'GET');
	},
	post:function(callback,url,data){
		return this.rpc(callback,url,data,'POST');
	}
}
TQE.toolbarBottons.insertimage.click=function($,sender)
{
	var o=TQE.find($.objId+'InsertImage');
	if(null==o){
		var resStrInsertImage='插入图片';
		var resStrInsertImageUI='图片网址:<input type="text" id="url" value="" size=30 />';
		if($.config.server_url_r2l) resStrInsertImageUI+='<input type=button value="抓取到本地" id="r2l" name="r2l" />';
		resStrInsertImageUI+='<br />替换文本:<input name="alt" type="text" id="alt" size="20" /><br />尺寸:<input name="width" type="text" id="width" size="4" /> &times; <input name="height" type="text" id="height" size="4" /> px &nbsp;<br />对齐:<select name="align" id="align"><option value="" >默认</option><option value="top">居上</option><option value="textTop">文本上方</option><option value="middle">居中</option><option value="absMiddle">绝对居中</option><option value="baseline">基线</option><option value="bottom">底部</option><option value="absBottom">绝对底部</option><option value="left">左</option><option value="right">右</option></select> &nbsp; &nbsp; 边框:<input name="border" type="text" id="border" size="5" />';
		var okClick=function(){
			TQE.hidePop();
			var es=this.form.elements;
			$.insertImage(es['url'].value,es['width'].value,es['height'].value,es['border'].value, es['alt'].value,es['align'].value);
			return false;
			};
		o = $._popFormUI($.objId+'InsertImage',resStrInsertImage, resStrInsertImageUI, okClick ,['width','height','border'], $.config.imageUploadUrl,$.config.imageFileTypes, $.config.imageFileSize, 'image');
		if($.config.server_url_r2l){
			TQE._tags(o,'FORM')[0].elements['r2l'].onclick=function(){
				var es=this.form.elements;
				if(''==es['url'].value) return;
				TQE.ajax.post(function(str){
					try{
						var result=eval('['+str+']')[0];
						if(result.code==0){
							es['url'].value=result.url;
						}else{
							alert('抓取出错.\n出错码:' + result.message+'\n' + result.message);
						}
					}catch(e){
						alert('返值出错:'+str);
					}
				}, $.config.server_url_r2l+'?fileurl='+es['url'].value);
				return false;
				};
			;
			
		}
		TQE.drag(o);
	}
	if(!TQE.pop(o,sender)) return;
	var f = TQE._tags(o,'FORM')[0],
		es = f.elements,
		r=$._getRange(),
		n=r.commonAncestorContainer;
	f.reset();
	if(n){ //标准dom
		if(!r.collapsed && r.startContainer == r.endContainer && r.startOffset - r.endOffset < 2 && r.startContainer.hasChildNodes()){
			n=r.startContainer.childNodes[r.startOffset];
		}
		if(n.tagName!='IMG' && isIE9 && ''===r.toString()){
			if(undefined===r.startContainer.length && r.startContainer.firstChild===r.endContainer.previousSibling)n=r.startContainer.firstChild;
			else if(r.endContainer.lastChild===r.startContainer.nextSibling)n=r.endContainer.lastChild;
			else if(r.startContainer.length == r.startOffset && r.endOffset==0 && r.startContainer.nextSibling==r.endContainer.previousSibling){
				n=r.startContainer.nextSibling;
			}
		} 
		if(!n || n.tagName!='IMG') n=null; 
	}else if(r.length && r.item(0).tagName=='IMG'){	//isIE, ie6,7,8
		n=r.item(0);
	}
	if(n && 'IMG'==n.nodeName){
		 es['url'].value=n.getAttribute('src');
		 es['width'].value=n.width;
		 es['height'].value=n.height;
		 es['border'].value=n.border;
		 es['alt'].value=n.alt;
		 $.__selectOption(es['align'],n.align);
	}
	es['url'].focus();
}
